﻿<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>SIM卡管理</title>
  <!-- import CSS -->
  <link rel="shortcut icon" href="../favicon.ico">
  <link rel="stylesheet" href="../plugins/ElementUI/index-2.3.9.css">
  <link href="../css/common.css" rel="stylesheet">
  <!-- import Vue before Element -->
  <script src="../plugins/ElementUI/vue-2.5.16.js"></script>
  <script src="../plugins/ElementUI/index-2.3.9.js"></script>
  <script src="../plugins/ElementUI/vue-resource.min.js"></script>
</head>
<body>
  <div id="app" v-cloak v-show="addShow" class="animated fadeInRight">
    <el-form ref="form" :model="form" label-width="80px" style="width: 900px">
      <el-row>
        <el-col :span="11">
          <el-form-item label="查询时间">
              <el-date-picker
                v-model="form.timeValue"
                type="datetimerange"
                align="center"
                size="small"
                style="width:335px;font-size: 12px"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                value-format="yyyy-MM-dd HH:mm:ss"
                :default-time="['00:00:00', '23:59:59']">
              </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="SIM卡号">
            <el-input v-model="form.simNo" clearable size="small"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="启用状态">
              <el-select v-model="form.inUse" clearable placeholder="请选择" size="small">
                  <el-option v-for="item in optionInUse" :key="item.value" :label="item.label" :value="item.value"></el-option>
              </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="1">
          <el-form-item>
            <el-button type="primary" size="small" @click="onSubmit" v-show="resourceMap.querySimCard">&nbsp;&nbsp;查询&nbsp;&nbsp;</el-button>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div>
      <el-button type="primary" size="small" icon="el-icon-circle-plus" @click="NewAdd" v-show="resourceMap.addSimCard">新增</el-button>
      <el-button type="primary" size="small" icon="el-icon-delete" @click="onSelectDel" v-show="resourceMap.deleteSimCard" >删除选中</el-button>
    </div>
    <br>
    <!-- table -->
    <el-table :data="tableData.list" border size="small" :max-height="windowHeight" style="width: 100%"  @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column type="index" ></el-table-column>      
      <el-table-column prop="simNo" sortable label="卡号"></el-table-column>
      <el-table-column prop="producer" sortable label="运营商"></el-table-column>
      <el-table-column prop="inUse" sortable label="启用状态">
        <template slot-scope="scope">
            <span class="label-outuse" v-if="scope.row.inUse">未启用</span>
            <span class="label-inuse" v-else>已启用</span>
        </template>
      </el-table-column>
      <el-table-column prop="gmt_modified" sortable label="修改时间" show-overflow-tooltip></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index,scope.row)" v-show="resourceMap.updateSimCard">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <br>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page.sync="form.page"
      :page-sizes="[20,50,100,150,200]"
      :page-size="form.pageSize"
      layout="sizes, prev, pager, next"
      :total="tableData.totalCount">
    </el-pagination> 
    <!-- dialog NewAdd-->
    <el-dialog :title="changeTitle" :visible.sync="dialogNewAdd" width="35%">
      <el-form :model="formDialogAdd">
        <el-row>
          <el-col :span="20">
            <el-form-item label="SIM卡号:" :label-width="formLabelWidth">
              <el-input v-model="formDialogAdd.simNo" size="small" auto-complete="off" style="width:100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="运营商：" :label-width="formLabelWidth">
              <el-input v-model="formDialogAdd.producer" size="small" auto-complete="off" style="width:100%"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="是否启用：" :label-width="formLabelWidth">
                <el-select v-model="formDialogAdd.inUse" clearable placeholder="请选择" size="small" style="width:100%">
                  <el-option v-for="item in optionInUse" :key="item.value" :label="item.label" :value="item.value"></el-option>
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="20">
            <el-form-item label="备注信息：" :label-width="formLabelWidth">
              <el-input v-model="formDialogAdd.remarks" size="small" auto-complete="off" style="width:100%"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogNewAdd = false" size="small">取 消</el-button>
        <el-button type="primary" @click="newAddSubmit" size="small">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</body>
  <script src="../plugins/Underscore/underscore-min.js"></script>
  <script src="../js/ApiRequest.js"></script>
  <script>
    var vm = new Vue({
      el: '#app',
      data: function() {
        return { 
          addShow:false,
          resourceMap:storageLocal.getName('simCard'),
          tableData: [],
          form: {
            page:1,
            pageSize:20,
          },
          changeTitle:'',
          dialogNewAdd: false,
          formDialogAdd: {},
          formLabelWidth: '120px',
          windowHeight: (window.innerHeight||(document.documentElement&&document.documentElement.clientHeight)||document.body.clientHeight) - 220,
          multipleSelection:[],
          optionInUse:[{
            value:0,
            label:'启用'
          },{
            value:1,
            label:'不启用'
          }]
        }
      },
      mounted:function(){
        this.$nextTick(function(){
          this.requestModel()
        })
      },
      updated:function(){
        this.addShow = true
      },
      methods: {
          NewAdd:function(){
            this.formDialogAdd = {}
            this.dialogNewAdd = true
            this.changeTitle = "新增SIM卡"
          },
          onSubmit:function() {//查询提交
            this.currentPage = 1;
            this.requestModel()
          },
          handleSelectionChange:function(val){
            this.multipleSelection = val;
          },
          newAddSubmit:function(){//新增用户,更新用户 -- 提交
            var _this = this;
            var data = {
              id: this.formDialogAdd.id?this.formDialogAdd.id:'',
              simNo:this.formDialogAdd.simNo,
              producer:this.formDialogAdd.producer,
              inUse:this.formDialogAdd.inUse,
              remarks:this.formDialogAdd.remarks,
            }
            if(data.id != ''){//更新 
              resourceRequst("/simCard/updateSimCard",data,function(res){
                  _this.$message({message: '修改成功',type: 'success'});
                  _this.requestModel()
              })
            }else{//新增
              resourceRequst("/simCard/addSimCard",data,function(res){
                  _this.tableData.list.unshift(res.simCardEntity);
                  _this.$message({
                    message: '添加成功',
                    type: 'success'
                  });
              })
            }
            _this.dialogNewAdd = false;
          },
          onSelectDel:function() {//删除操作
            var _this = this;
            if(this.multipleSelection.length == 0){
              this.$message({ showClose: true, message: '提示，还未选中对象', type: 'warning', duration:1500 });
              return
            }
            var arry = _.map(_this.multipleSelection, function(num){ 
              return num.id; 
            });
            this.$alert('此操作将删除选中数据, 是否继续?', '提示', {
              confirmButtonText: '确定',
              showCancelButton:true,
              type: 'warning',
              callback: function(action){
                if (action == "confirm") {
                  var data = {allKeys:arry}
                  resourceRequst("/simCard/deleteSimCard",data,function(res){
                    var table = _.filter(_this.tableData.list, function(item){ 
                      return arry.indexOf(item.id) < 0 
                    });
                    _this.tableData.list = table;
                    _this.$message({ type: 'success', message: "删除成功！" });
                  })
                }
              }
            });
          },
          handleEdit:function(index, row) {//编辑
            var item = JSON.stringify(row)
            this.formDialogAdd = JSON.parse(item);
            this.dialogNewAdd = true;
            this.changeTitle = "编辑SIM卡"
          },
          handleSizeChange:function(val) {
            this.form.page = 1;
            this.form.pageSize = val;
            this.requestModel()
          },
          handleCurrentChange:function(val) {
            this.requestModel()
          },
          requestModel:function(){
            var _this = this;
            var data = {
              page:this.form.page?this.form.page:1,
              pageSize:this.form.pageSize?this.form.pageSize:20,
              startTime:this.form.timeValue?this.form.timeValue[0]:"",
              endTime:this.form.timeValue?this.form.timeValue[1]:"",
              simNo:this.form.simNo?this.form.simNo:"",
              inUse:this.form.inUse,
            }
            resourceRequst("/simCard/querySimCard",data,function(res){
              _this.tableData = res
            })
          }
      }
    })
  </script>
</html>